package com.gec.hawaste.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gec.hawaste.entity.Examine;
import com.gec.hawaste.mapper.ExamineMapper;
import com.gec.hawaste.service.IExamineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gec.hawaste.vo.ExamineDo;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenxys
 * @since 2022-07-01
 */
@Service
public class ExamineServiceImpl extends ServiceImpl<ExamineMapper, Examine> implements IExamineService {

    /**
     * 拼接动态sql
     * @author chenxys
     * @param page 分页查询
     * @param params 条件查询参数
     * @return com.baomidou.mybatisplus.core.metadata.IPage<com.gec.hawaste.vo.ExamineDo>
     */
    @Override
    public IPage<ExamineDo> selectByCondition(IPage<ExamineDo> page, Map<String, Object> params) {
        // 创建查询条件
        QueryWrapper<ExamineDo> queryWrapper = new QueryWrapper<>();
        queryWrapper.apply("examine.del_flag=0 and examine.examine_user_id = sys_user.id and sys_user.office_id = sys_office.id ")
                        //  public Children eq(boolean condition, R column, Object val)
                        .eq(params.containsKey("officeId")&&!ObjectUtils.isEmpty(params.get("officeId")),"sys_office.id",params.get("officeId"))
                        .eq(params.containsKey("type")&&!ObjectUtils.isEmpty(params.get("type")),"examine.type ",params.get("type"))
                        .like(params.containsKey("name")&&!ObjectUtils.isEmpty(params.get("name")),"sys_user.name",params.get("name"));

        return baseMapper.selectByCondition(page,queryWrapper);
    }
}
